package com.clps.algorithm.chapter14.翻转字符串;

public class demo01 {
    public static void main(String[] args) {

    }

    public int minFlipsMonoIncr(String s) {
        int len = s.length();
        if (len == 0) {
            if (len == 0) {
                return 0;
            }

            int[][] dp = new int[2][2];
            char ch = s.charAt(0);
            dp[0][0] = ch == '0' ? 0 : 1;
            dp[1][0] = ch == '1' ? 0 : 1;

            for (int i = 0; i < len; i++) {
                ch = s.charAt(i);
                int prev0 = dp[0][(i - 1) % 2];
                int pre1 = dp[1][(i - 1) % 2];
                dp[0][i % 2] = prev0 + (ch == '0' ? 0 : 1);
                dp[1][i % 2] = Math.min(prev0, pre1) + (ch == '1' ? 0 : 1);
            }

        }
        return len;
    }
}
